package jsi.search;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Map.Entry;

public class Roi {

	public Roi() {
	}

	public static void main(String[] args) {
		
		try {
            InputStream is = new FileInputStream(new File("roi_frontend.log"));
            InputStreamReader r = new InputStreamReader(is); //, "iso-8859-2"

            BufferedReader in = new BufferedReader(r);
            String line = null;

            List selected=new LinkedList();
            SortedSet diff1 = new TreeSet();
            SortedSet diff2 = new TreeSet();
            
            while ((line = in.readLine()) != null){

                    String [] words = line.split("\\|");
                    if (words[0].matches("hit") || words[0].matches("out") || words[0].matches("hitout")){
                            String log = words[0] + '|' + words[4];
                            diff1.add(log);
                            if (words.length >= 7) log += "|" + words[6];
                            selected.add(log);
                            diff2.add(log);
    //                      System.out.println(log);
                    }
            }

            System.out.println("processed ==================================================================");
            Collections.sort(selected);
            
            for (Object s:selected){
                    System.out.println(s);
            }
            
            System.out.println("================================================= set wiekszy");
            for (Object s:diff2){
                System.out.println(s);
            }
            System.out.println("================================================= set mniejszy");
            for (Object s:diff1){
                System.out.println(s);
            }
    } catch (Exception e) {
            e.printStackTrace();
    }

	}
	
	static void  main2(){
		try {
            InputStream is = new FileInputStream(new File("roi_api.log"));
            InputStreamReader r = new InputStreamReader(is); //, "iso-8859-2"

            BufferedReader in = new BufferedReader(r);
            String line = null;

           HashMap<String, Integer> map = new HashMap<String, Integer>();

            while ((line = in.readLine()) != null){

                    String [] words = line.split("\\|");
                            String log = words[0] ;
                    Integer val = map.get(log);
                    if (val != null) {
                    	val++; 
                    } else {
                    	map.put(log, 0);
                    }
            }

            System.out.println("================================================= set mniejszy");
            for (Entry<String, Integer> e:map.entrySet()){
                System.out.println(e.getKey() + "  " + e.getValue());
            }
    } catch (Exception e) {
            e.printStackTrace();
    }

	}

}
